package com.quyeying.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.quyeying.entity.TblBusinessCategoryEntity;
import com.quyeying.mapper.TblBusinessCategoryDao;
import com.quyeying.service.TblBusinessCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ReturnPageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
* <p>
 * 经营类目表 服务实现类
 * </p>
*
* @author jll
* @since 2022-12-14
*/
@Service
public class TblBusinessCategoryServiceImpl extends ServiceImpl<TblBusinessCategoryDao, TblBusinessCategoryEntity> implements TblBusinessCategoryService {

    @Override
    public R findListByPage(Integer page, Integer pageCount){
        IPage<TblBusinessCategoryEntity> wherePage = new Page<>(page, pageCount);
        TblBusinessCategoryEntity where = new TblBusinessCategoryEntity();
        IPage<TblBusinessCategoryEntity> iPage = baseMapper.selectPage(wherePage, Wrappers.query(where));
        return R.success(ReturnPageData.fillingData(iPage));
    }

    @Override
    public R add(TblBusinessCategoryEntity tblBusinessCategoryEntity){
        baseMapper.insert(tblBusinessCategoryEntity);
        return R.success();
    }

    @Override
    public R delete(Long id){
        baseMapper.deleteById(id);
        return R.success();
    }

    @Override
    public R updateData(TblBusinessCategoryEntity tblBusinessCategoryEntity){
        baseMapper.updateById(tblBusinessCategoryEntity);
        return R.success();
    }

    @Override
    public R findById(Long id){
        TblBusinessCategoryEntity tblBusinessCategoryEntity = baseMapper.selectById(id);
        return R.success(tblBusinessCategoryEntity);
    }

    @Override
    public R findList() {
        List<TblBusinessCategoryEntity> tblBusinessCategoryEntities = baseMapper.selectList(new QueryWrapper<>());
        return R.success(tblBusinessCategoryEntities);
    }
}
